package com.ccc.demoboot.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ccc.demoboot.common.R;
import com.ccc.demoboot.pojo.Code;
import com.ccc.demoboot.service.CodeService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @Author wz
 * @Date 2024/6/14 8:54
 * @PackageName:com.ccc.demoboot.controller
 * @ClassName: CodeController
 */
@RequestMapping("/code")
@RestController
public class CodeController {

    @Autowired
    CodeService codeService;

    /**
     * 分頁查詢所有物資信息
     * @param page
     * @return
     */
    @PostMapping("/select/{page}")
    public R select(@PathVariable("page") int page) {
        PageHelper.startPage(page, 5);//第一个参数表示第几页,第二个参数表示每页的条数
        List<Code> list = this.codeService.list();
        PageInfo<Code> menuPageInfo = new PageInfo<>(list);
        return new R().add("pageInfo", menuPageInfo);
    }

@PostMapping("/selecttj")
    public R selectTj(@RequestBody Code code){
        List<Code> list=this.codeService.selectTj(code.getMaterialname());
        return new R().add("list",list);
    }


    /**
     * 获取一二级信息
     * @return
     */
    @PostMapping("/category")
    public R category(){
        List<Code> list = this.codeService.listmy();
        return new R().add("list",list);
    }

    /**
     * 获取一二三级信息
     * @return
     */
    @PostMapping("/warecategory" )
    public R wareCategory(){
        List<Code> list = this.codeService.list();
        return new R().add("list",list);
    }



    /**
     * 根据id获取物资编码
     * @param code
     * @return
     */
    @PostMapping("/codematerialid")
    public R codematerialId(@RequestBody Code code){
        Code byId = this.codeService.getById(code.getId());
        return new R().add("byid",byId);
    }

    /**
     * 生成物资编码
     * @param code
     * @return
     */
    @PostMapping("/warematerialid")
    public R wareMaterialId(@RequestBody Code code){
        String codeid=this.codeService.wareMaterialId(code);
            return new R().add("codeid",codeid);
    }

    /**
     * 根据查询物资信息
     * @param code
     * @return
     */
    @PostMapping("/codeSelect")
    public R searchSelect(@RequestBody Code code) {
        QueryWrapper<Code> areaQueryWrapper = new QueryWrapper<>();
        areaQueryWrapper.setEntity(code);
        List<Code> list = this.codeService.list(areaQueryWrapper);
        return new R().add("list", list);
    }

    /**
     * uniAPP获取仓库 区域 货架的一二三级信息
     * @return
     */
    @PostMapping("/uniWarecategory" )
    public R uniWarecategory(){
        List<Code> list = this.codeService.list();
        return new R().add("list",list);
    }
}
